package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自媒体频道管理
 */
@RestController
@RequestMapping("/api/v1/channel")
@Slf4j
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @Autowired

    /**
     * 查询所有频道
     */
    @GetMapping("/channels")
    public ResponseResult channels(){
        log.info("【查询所有频道】");
        return wmChannelService.findAllChannel();
    }

    /**
     * 根据频道名称模糊查询
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody  ChannelDto channelDto){
        log.info("【模糊查询所有频道】");
        return wmChannelService.list(channelDto);
    }
    /**
     * 保存频道
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){
        log.info("【保存频道】");
        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 删除频道
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id){
        log.info("【删除频道】");
        return wmChannelService.deleteChannel(id);
    }

    /**
     * 修改频道
     */
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){
        log.info("【修改频道】");
        return wmChannelService.updateChannel(wmChannel);
    }


}
